package inventory.stockManagement.view;

import inventory.reports.view.CurrentStockReportView;
import inventory.reports.view.InwardReportView;
import inventory.reports.view.OutwardReportView;
import inventory.stockManagement.controller.LiveGinControler;
import inventory.stockManagement.controller.LiveIssueSlipController;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;
import javax.swing.JLabel;

import viewframework.UIFrameWork;

import common.controller.GinController;
import common.controller.IssueSlipController;
import common.view.GinView;
import common.view.IssueSlipView;



import java.awt.Font;
import java.awt.Dimension;
import java.awt.SystemColor;

public class StockManagementMainView extends JPanel implements MouseListener 
{
	private JLabel lblOpenGin;
	private JLabel lblOpenIssueSlip;
	private JLabel lblMaterialOutward;
	private JLabel lblMaterialInward;
	private JLabel[]leftMenu;
	private JToolBar toolBar;
	private SpringLayout sl;
	
	public StockManagementMainView() 
	{
		sl= new SpringLayout();
		setLayout(sl);
		setSize(1050,550);
			
		toolBar = new JToolBar();
		toolBar.setBackground(SystemColor.inactiveCaption);
		toolBar.setBorder(null);
		toolBar.setOrientation(SwingConstants.VERTICAL);
		sl.putConstraint(sl.SOUTH, toolBar, 0, sl.SOUTH, this);
		sl.putConstraint(sl.NORTH, toolBar, 1, sl.NORTH, this);
		sl.putConstraint(sl.WEST, toolBar, 0, sl.WEST, this);
		sl.putConstraint(sl.EAST, toolBar, 180, sl.WEST, this);
		makeLeftMenu();
		addButtonsInToolBar();
		addButtonListener();
		add(toolBar);
	}
	
	
	
	private void makeLeftMenu()
	{
		leftMenu=new JLabel[4];
		
		lblOpenGin=new JLabel("Open Gin",SwingConstants.CENTER);
		lblOpenGin.setPreferredSize(new Dimension(72, 40));
		lblOpenGin.setMinimumSize(new Dimension(180, 40));
		lblOpenGin.setMaximumSize(new Dimension(180, 40));
		lblOpenGin.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		leftMenu[0]=lblOpenGin;
		
		lblOpenIssueSlip=new JLabel("Open Issue Slip",SwingConstants.CENTER);
		lblOpenIssueSlip.setPreferredSize(new Dimension(72, 40));
		lblOpenIssueSlip.setMinimumSize(new Dimension(180, 40));
		lblOpenIssueSlip.setMaximumSize(new Dimension(180, 40));
		lblOpenIssueSlip.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		leftMenu[1]=lblOpenIssueSlip;
		
		lblMaterialOutward=new JLabel("Material Outward",SwingConstants.CENTER);
		lblMaterialOutward.setPreferredSize(new Dimension(72, 40));
		lblMaterialOutward.setMinimumSize(new Dimension(180, 40));
		lblMaterialOutward.setMaximumSize(new Dimension(180, 40));
		lblMaterialOutward.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		leftMenu[2]=lblMaterialOutward;
		
		lblMaterialInward=new JLabel("Material Inward",SwingConstants.CENTER);
		lblMaterialInward.setPreferredSize(new Dimension(72, 40));
		lblMaterialInward.setMinimumSize(new Dimension(180, 40));
		lblMaterialInward.setMaximumSize(new Dimension(180, 40));
		lblMaterialInward.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		leftMenu[3]=lblMaterialInward;
		
		for(int k=0;k<leftMenu.length;k++)
			leftMenu[k].setBorder(null);
	}
	
	
	private void addButtonsInToolBar()
	{
		toolBar.add(lblOpenGin);
		toolBar.addSeparator();
		toolBar.add(lblOpenIssueSlip);
		toolBar.addSeparator();
		toolBar.add(lblMaterialOutward);
		toolBar.addSeparator();
		toolBar.add(lblMaterialInward);
		toolBar.addSeparator();
	}
	
	private void addButtonListener()
	{
		for(JLabel temp:this.leftMenu)
			 temp.addMouseListener(this);
	}
	
	@Override
	public void mouseClicked(MouseEvent arg0) 
	{
		if(arg0.getSource() instanceof JLabel)
		{
			JLabel label=(JLabel) arg0.getSource();
			
			if(label==lblOpenGin)
			{
				OpenGinView ogv=new OpenGinView();
				LiveGinControler cntrl = new LiveGinControler(ogv,null);
				UIFrameWork.setReportComponent(sl, ogv, this,2);
			}
				
			if(label==lblOpenIssueSlip)
			{
				OpenIssueSlipView oisv=new OpenIssueSlipView();
				LiveIssueSlipController cntrl1 = new LiveIssueSlipController(oisv,null);
				UIFrameWork.setReportComponent(sl,oisv, this,2);
			}
			
			if(label==lblMaterialInward)
			{
				IssueSlipView isv=new IssueSlipView();
				try {
					IssueSlipController cntrl = new IssueSlipController(isv,null);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				UIFrameWork.setReportComponent(sl, isv, this,2);
			}
			
			if(label==lblMaterialOutward)
			{
				GinView gv=new GinView();
				try {
					GinController cntrl = new GinController(gv,null);
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				UIFrameWork.setReportComponent(sl, gv, this,2);
			}
		}
	}


	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	
}
